<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css}" type="text/css">
    <link th:href="@{/erp/Widget/icheck/icheck.css}" rel="stylesheet" type="text/css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome-ie7.min.css}"/>
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}"/>
    <![endif]-->
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script type="text/javascript" th:src="@{/erp/js/H-ui.js}"></script>
    <script type="text/javascript" th:src="@{/erp/js/H-ui.admin.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>
    <script type="text/javascript" th:src="@{/erp/Widget/zTree/js/jquery.ztree.all-3.5.min.js}"></script>
    <script th:src="@{/erp/js/lrtk.js}" type="text/javascript"></script>

    <script>
        $("#pd").click(function () {
            window.location.href = "inventory_adjustment.html";
        })
    </script>

    <title>仓库预警</title>
</head>

<body>
<div class="margin clearfix">
    <div class="Shops_Audit">
        <div class="search_style">
            <form>
                <ul class="search_content clearfix">
                    <li>仓库名称<select style="width: 150px; margin-left: 10px;" name="ware">
                        <option value="">请选择仓库</option>
                        <option th:each="ware:${wares}" th:text="${ware}" th:value="${ware}">
                    </select>
                    </li>
                    <li><label class="l_f">产品名称</label><input name="product" type="text" class="text_add"
                                                              placeholder="输入产品名称"
                                                              style=" width:150px"/></li>
                    <li style="width:90px;">
                        <button type="button" class="btn_search" id="search"><i class="icon-search"></i>查询</button>
                    </li>
                    <li class="">
                        <label class="l_f" style="color: #FF0000;font-size: 16px;font-weight: bold;"
                               id="messageCount"></label>
                    </li>
                </ul>
            </form>

            <br><br>
            <form id="addWarning">
                <ul class="search_content clearfix">
                    <li>仓库名称<select style="width: 150px; margin-left: 10px;" name="warehouseId">
                        <option value="">请选择仓库</option>
                        <option th:each="wareId:${wareIds}" th:text="${wareId.ware_name}" th:value="${wareId.id}">
                    </select>
                    </li>
                    <li>产品名称<select style="width: 150px; margin-left: 10px;" name="productId">
                        <option value="">请选择产品</option>
                        <option th:each="product:${products}" th:text="${product.product}" th:value="${product.product_no}">
                    </select>
                    </li>
                    <li><label class="l_f">预警值</label><input name="warningNum" type="text" class="text_add"
                                                              placeholder="输入预警值"
                                                              style=" width:150px"/></li>
                    <li style="width:90px;">
                        <button type="button" class="btn_search" id="addWar" style="width: 150px"><i class="icon-search"></i>设置预警值</button>
                    </li>

                </ul>
            </form>
        </div>
    </div>
    <!--申请列表-->
    <div class="h_products_list clearfix" id="products_list">
        <div id="testIframe">
            <table class="table table-striped table-bordered table-hover" id="sample-table">
                <thead>
                <tr>
                    <th width="60px">序号</th>
                    <th width="80px">仓库id</th>
                    <th hidden="hidden">仓库名称</th>
                    <th width="80px">产品编号</th>
                    <th width="100">产品名称</th>
                    <th width="80px">库存量</th>
                    <th width="100">状态</th>
                    <th width="100">备注</th>
                    <th width="100">当前产品预警值</th>
                    <th width="100">设置预警值</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="add_menber" id="add_menber_style" style="display:none;">

    <ul class=" page-content">
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>仓库名称：</label>
            <div class="formControls " id="ware">
                宿迁仓
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>产品名称：</label>

            <div class="formControls " id="product">
                64ma速派电池
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>当前产品预警值：</label>

            <div class="formControls " id="nowWarningNum">
                400
            </div>
        </div>
        <form id="warning">
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span><i style="color: #f00">*</i>仓库id：</label>
                <div class="formControls ">
                    <input type="text" class="input-text" value="" placeholder="" id="warehouseId" name="warehouseId">
                </div>
            </div>
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span><i style="color: #f00">*</i>产品id：</label>
                <div class="formControls ">
                    <input type="text" class="input-text" value="" placeholder="" id="productId" name="productId">
                </div>
            </div>
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span><i style="color: #f00">*</i>设置预警值：</label>
                <div class="formControls ">
                    <input type="text" class="input-text" onblur="testwarningNum()" placeholder="" id="warningNum"
                           name="warningNum">
                    <span id="warningText" th:text="预警值有误" style="display: none;color: red"></span>
                </div>
            </div>
        </form>
    </ul>
</div>
</div>
</div>
</body>
</html>
<script>

    $(function () {
        var table = $('#sample-table').DataTable({
            searching: false,
            serverSide: true,   //开始服务器分页
            aoColumnDefs: [
                {"orderable": false, "aTargets": [0, 1, 2, 3, 4, 5]}// 制定列不参与排序
            ],
            ajax: {
                url: '/warning/page',
                type: 'post',
                data: function (d) {
                    var data = $('form').serialize();   //获取查询条件

                    //获取分页信息
                    var searchParams = {
                        start: d.start,
                        length: d.length,
                    };
                    data = data + '&' + $.param(searchParams);
                    return data;
                }
            },
            columns: [
                {
                    "data": "ware_name",
                    'sDefaultContent': '',
                    "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).text(row + 1);
                    }
                },
                {
                    "data": "ware_id",
                    'sDefaultContent': '',
                    "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).css("display", "none");
                    }
                },
                {"data": "ware_name", 'sDefaultContent': ''},
                {"data": "product_no", 'sDefaultContent': ''},
                {"data": "product", 'sDefaultContent': ''},
                {"data": "cou", 'sDefaultContent': ''},
                {
                    "data": "cou", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).text('库存不足')
                        $(td).css("color", "red")
                    }
                },
                {"data": "remark", 'sDefaultContent': ''},
                {"data": "warning_num", 'sDefaultContent': ''},
                {
                    "data": "cou", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('<button type="button" class="shez_id btn btn-primary"><i class="icon-edit bigger-120"></i></button>')
                    }
                }
            ]

        });

        //搜索按钮事件
        $('#search').click(function () {
            table.ajax.reload();
            countMessage();
        })
        countMessage();

    })

    /*条数信息显示*/
    function countMessage() {
        $.ajax({
            url: '/warning/count',
            data: $('form').serialize(),
            success: function (d) {
                if(d.rs){
                    var data = d.data;$("#messageCount").text("当前仓库预警信息有" + data + "条")
                    $("#messageCount").css("color", "red")
                }else{
                    layer.msg(d.msg,{icon:2,time:2000})
                }

            }

        })
    }

    var reg = /^\d{1,}$/
    var pattern = new RegExp(reg);

    function testwarningNum() {
        if (!pattern.test($("#warningNum").val())) {
            $("#warningText").show();
        } else {
            $("#warningText").hide();
        }
    }
    /*添加预警值*/

    $("body").on("click","#addWar",function () {
        $.ajax({
            type: 'post',
            url:'[[@{/warning/addWarning}]]',
            data:$("#addWarning").serialize(),
            success:function (d) {
                if(!d.rs){
                    layer.msg("预警值设置失败！",{icon:2,time:2000});
                    return;
                }
                layer.alert('预警值设置成功！', {
                    title: '提示框',
                    icon: 1,
                });
                window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
            }
        })
    })
    $(function () {
        $("body").on("click", ".shez_id", function () {
            $("#ware").text($(this).closest('tr').find('td').eq(1).text());
            $("#product").text($(this).closest('tr').find('td').eq(4).text());
            $("#nowWarningNum").text($(this).closest('tr').find('td').eq(8).text());
            $("#warehouseId").val($(this).closest('tr').find('td').eq(1).text());
            $("#productId").val($(this).closest('tr').find('td').eq(3).text());
            $("#warningNum").val("");
            layer.open({
                type: 1,
                title: '设置当前预警值',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['600px', ''],
                content: $('#add_menber_style'),
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    var num = 0;
                    var str = "";
                    $(".add_menber input[type$='text']").each(function (n) {
                        if ($(this).val() == "") {

                            layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                                title: '提示框',
                                icon: 0,
                            });
                            num++;
                            return false;
                        }
                    });
                    if (num > 0) {
                        return false;
                    } else {
                        if (pattern.test($("#warningNum").val())) {
                            $.ajax({
                                type: 'post',
                                url: '/warning/updateWarningNum',
                                data: $("#warning").serialize(),
                                /*预警值设置成功提示框*/
                                success: function (d) {
                                    if(!d.rs){
                                        layer.msg("设置失败",{icon:2,time:2000});
                                        return;
                                    }
                                    layer.alert('设置成功！', {
                                        title: '提示框',
                                        icon: 1,
                                    });
                                    layer.close(index);
                                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                                    countMessage();
                                },
                                /*预警值设置失败提示框*/
                                error: function () {
                                    layer.alert('设置失败，请检查信息！', {
                                        title: '提示框',
                                        icon: 0,
                                    });
                                }
                            });
                        } else {
                            layer.alert('预警值有误！', {
                                title: '提示框',
                                icon: 0,
                            });
                        }
                    }
                }
            });
        });
    });
    //面包屑返回值
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.iframeAuto(index);
    $('.Refund_detailed').on('click', function () {
        var cname = $(this).attr("title");
        var chref = $(this).attr("href");
        var cnames = parent.$('.Current_page').html();
        var herf = parent.$("#iframe").attr("src");
        parent.$('#parentIframe').html(cname);
        parent.$('#iframe').attr("src", chref).ready();
        ;
        parent.$('#parentIframe').css("display", "inline-block");
        parent.$('.Current_page').attr({"name": herf, "href": "javascript:void(0)"}).css({
            "color": "#4c8fbd",
            "cursor": "pointer"
        });
        //parent.$('.Current_page').html("<a href='javascript:void(0)' name="+herf+" class='iframeurl'>" + cnames + "</a>");
        parent.layer.close(index);
    });
</script>
